package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.ServiceDealPeopleBean;
import com.renwei.yunlong.bean.SponsorBean;
import com.zyf.fwms.commonlibrary.utils.AutoUtils;

import java.util.List;

/**
 * 服务商  工单  处理人 adapter
 *
 * Created by Administrator on 2017/9/13.
 */

public class ServiceSelectDealPeopleAdapter extends RecyclerView.Adapter<ServiceSelectDealPeopleAdapter.ServiceSelectDealPeopleViewHolder>{

    private Context context;
    private LayoutInflater inflater;
    List<ServiceDealPeopleBean.Rows> mList;

    private OnItemClickListener mOnItemClickListener;

    public ServiceSelectDealPeopleAdapter(Context context, List<ServiceDealPeopleBean.Rows> mList){
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.mList = mList;
    }

    @Override
    public ServiceSelectDealPeopleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_select_sponsor,null);
        AutoUtils.auto(view);
        return new ServiceSelectDealPeopleViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ServiceSelectDealPeopleViewHolder holder, int position) {
        final ServiceDealPeopleBean.Rows rows = mList.get(position);
        Glide.with(context).load(rows.getAvatar()).into(holder.ivHead);
        holder.tvName.setText(rows.getName());
        holder.tvDepartment.setText(rows.getDepartmentName());
        holder.tvPhone.setText(rows.getMobilePhone());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int pos = holder.getLayoutPosition();
                mOnItemClickListener.onItemClick(holder.itemView,pos,rows.getName(),rows.getEmployeeId());
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList == null?0:mList.size();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){

        this.mOnItemClickListener = onItemClickListener;
    }
    public interface OnItemClickListener{
        void onItemClick(View view, int position, String name,String serviceEmployeeId);
    }


    static class ServiceSelectDealPeopleViewHolder extends RecyclerView.ViewHolder{

        private View itemView;
        private ImageView ivHead;
        private TextView tvName;//名称
        private TextView tvDepartment;//部门
        private TextView tvPhone;

        public ServiceSelectDealPeopleViewHolder(View view) {
            super(view);
            itemView = view;
            ivHead = (ImageView) itemView.findViewById(R.id.iv_head);
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            tvDepartment = (TextView) itemView.findViewById(R.id.tv_department);
            tvPhone = (TextView) itemView.findViewById(R.id.tv_phone);
        }
    }
}
